<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline';" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
        <meta charset="utf-8" />
        <title>PMS-business</title>
        <link rel="stylesheet" href="../../assets/css/bootstrap.css" />
		<link rel="stylesheet" href="../../assets/css/font-awesome.css" />
		<link rel="stylesheet" href="../../assets/css/ace-fonts.css" />
		<link rel="stylesheet" href="../../assets/css/ace.css" />
		<link rel="stylesheet" href="../../css/login/login.css" />
		<link rel="stylesheet" href="../../assets/css/jquery.gritter.css" />
		<script type="text/javascript">
			window.$ = window.jQuery = require('../../assets/js/jquery.js');
		</script>
		<style>
			.gritter-center-hs {
				  position: fixed;  
				  left: 43%; 
				  right: 33%;
				  top: 33%;
				  width:15%;      
				}
			.gritter-close { 
			    left: auto;
			    right: 3px;
			    background-image: none;
			    width: 18px;
			    height: 18px;
			    line-height: 17px;
			    text-align: center;
			    border: 2px solid transparent;
			    border-radius: 16px;
			    color: #E17B67;
			}
			.setUpInput{
				width: 486px;
				height: 30px;
				margin-left: 2px;
			}
		</style>
    </head>
    <body  class="login-layout light-login">
        <div class="main-container">
			<div class="main-content">
				<div class="row">
					<div class="col-sm-10 col-sm-offset-1">
						<div class="login-container">
							<div class="center">
								<h1>
									<span class="white" id="id-text2" style="color:#2aa1da !important;">PMS
										<span id="id-version" class="small"></span>
									</span>
								</h1>
								<h4 class="blue" id="id-company-text" style="color:#2aa1da !important;">&copy;business</h4>
							</div>
							<div class="space-6"></div>
							<div class="position-relative">
								<div id="login-box" class="login-box visible widget-box no-border" style="padding:0px;border:0px;box-shadow:none;">
									<div class="widget-body">
										<div class="widget-main">
											<h4 class="header blue lighter bigger">
												<i class="ace-icon fa fa-coffee green"></i>
												登录
											</h4>
											<div class="space-6"></div>
											<form id="validationLoginForm" onSubmit="return false;">
												<fieldset>
													<label class="block clearfix">
														<span class=" input-icon input-icon-right"><!--block-->
															<span class="label_name">酒店编号：</span>
															<input type="text" class="form-control focus" id="hotelID" name="hotelID" placeholder="酒店编号" style="text-transform:uppercase;"/>
															<i class="ace-icon fa fa-tag"></i> 
														</span>
														<span id="his_hotelID">

														</span>
													</label>
													<label class="block clearfix">
														<span class=" input-icon input-icon-right"><!--block-->
															<span class="label_name">部门号：</span>
															<input type="text" class="form-control" id="bmh" name="bmh" value="" placeholder="部门号" style="text-transform:uppercase;"/>
															<i class="ace-icon fa fa-desktop"></i>
														</span>
														<span id="his_bmh">

														</span>
													</label>
													<br>
													<label class="block clearfix">
														<span class="block input-icon input-icon-right">
															<span class="label_name">用户名：</span>
															<input type="text" class="form-control" id="userid" name="userid" value="" placeholder="用户名" style="text-transform:uppercase" />
															<i class="ace-icon fa fa-user"></i>
														</span>
													</label>
													<label class="block clearfix">
														<span class="block input-icon input-icon-right">
															<span class="label_name">密码：</span>
															<input type="password" class="form-control" id="upass" name="upass" placeholder="密码" style="text-transform:uppercase"/>
															<i class="ace-icon fa fa-lock"></i>
														</span>
													</label>
													<label class="block clearfix">
														<span class="block input-icon input-icon-right">
															<span class="label_name">班次：</span>
															<input type="text" class="form-control" id="kn" name="kn" placeholder="班次" style="text-transform:uppercase"/>
															<i class="ace-icon fa fa-shirtsinbulk"></i>
														</span>
													</label>
													<label class="inline" style="margin-top: 5px;">
														<small class="muted smaller-90" data-i18n="多选:">模式:</small>
														<input style="width: 15px;margin-left: 42px;height: 13px;" name="fullScreenMode" type="radio" value="pc"/>PC
														<input style="width: 15px;margin-left: 10px;height: 13px;" name="fullScreenMode" type="radio" value="op"/>触屏
													</label>
													<label class="block clearfix">
														<span class="block input-icon input-icon-right">
															<span id="loginTip" style="color:#A94442"></span>
														</span> 
													</label>
													<div class="space"></div>
													<div class="clearfix">
														<label class="middle">
															<input class="ace" type="checkbox" id="id-disable-check">
															<span class="lbl">&nbsp;记住历史</span>
														</label>
														<button id="loginButton" type="button" class="width-30 pull-right btn btn-sm btn-primary">
															<i class="ace-icon fa fa-key"></i>
															登录
															<span class="bigger-110"></span>
														</button>
														<button id="configButton" style="margin-right: 2px;" type="button" class="width-25 pull-right btn btn-sm btn-primary">
															<i class="ace-icon fa fa-cog"></i>
															设置
															<span class="bigger-110"></span>
														</button>
													</div>
													<div class="space-4"></div>
												</fieldset>
											</form>
											<div class="social-or-login center">
												<span class="bigger-110"></span>
											</div>
											<div class="space-6"></div>
											<div class="social-login center">
												<a class="btn btn-primary">
													<i id="updateIcon" class="ace-icon fa fa-check" style="margin-left: -1px;"></i>	
												</a>
											</div>
											<div class="social-login center">
												<span class="text-primary" id="updateMess">已是最新版</span> 
											</div>
										</div>
									</div>
								</div>
								<div class="login_keyboard" id="num_keyboard">
									<ul class="num-key clearfix mykb-box">
										<li class="num">
											<button type="button" class="btn btn-app btn-light dishes_each">7</button>
										</li>
										<li class="num">
											<button type="button" class="btn btn-app btn-light dishes_each">8</button>
										</li>
										<li class="num">
											<button type="button" class="btn btn-app btn-light dishes_each">9</button>
										</li>
										<li class="num">
											<button type="button" class="btn btn-app btn-light dishes_each">4</button>
										</li>
										<li class="num">
											<button type="button" class="btn btn-app btn-light dishes_each">5</button>
										</li>
										<li class="num">
											<button type="button" class="btn btn-app btn-light dishes_each">6</button>
										</li>
										<li class="num">
											<button type="button" class="btn btn-app btn-light dishes_each">1</button>
										</li>
										<li class="num">
											<button type="button" class="btn btn-app btn-light dishes_each">2</button>
										</li>
										<li class="num">
											<button type="button" class="btn btn-app btn-light dishes_each">3</button>
										</li>
										<li class="num keyboard_abc">
											<button type="button" class="btn btn-app btn-light dishes_each">abc</button>
										</li>
										<li class="num func">
											<button type="button" class="btn btn-app btn-light dishes_each">0</button>
										</li>
										<li class="num keyboard_bks">
											<button type="button" class="btn btn-app btn-light dishes_each">退格</button>
										</li>
									</ul>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		
		<!-- 字母键盘 -->
		<div class="keyboard" id="keyboard">
			<ul class="num-key clearfix mykb-box">
				<li class="letter">
					<button type="button" class="btn btn-app btn-light dishes_each">1</button>
				</li>
				<li class="letter">
					<button type="button" class="btn btn-app btn-light dishes_each">2</button>
				</li>
				<li class="letter">
					<button type="button" class="btn btn-app btn-light dishes_each">3</button>
				</li>
				<li class="letter">
					<button type="button" class="btn btn-app btn-light dishes_each">4</button>
				</li>
				<li class="letter">
					<button type="button" class="btn btn-app btn-light dishes_each">5</button>
				</li>
				<li class="letter">
					<button type="button" class="btn btn-app btn-light dishes_each">6</button>
				</li>
				<li class="letter">
					<button type="button" class="btn btn-app btn-light dishes_each">7</button>
				</li>
				<li class="letter">
					<button type="button" class="btn btn-app btn-light dishes_each">8</button>
				</li>
				<li class="letter">
					<button type="button" class="btn btn-app btn-light dishes_each">9</button>
				</li>
				<li class="letter">
					<button type="button" class="btn btn-app btn-light dishes_each">0</button>
				</li>
				<li class="letter">
					<button type="button" class="btn btn-app btn-light dishes_each">Q</button>
				</li>
				<li class="letter">
					<button type="button" class="btn btn-app btn-light dishes_each">W</button>
				</li>
				<li class="letter">
					<button type="button" class="btn btn-app btn-light dishes_each">E</button>
				</li>
				<li class="letter">
					<button type="button" class="btn btn-app btn-light dishes_each">R</button>
				</li>
				<li class="letter">
					<button type="button" class="btn btn-app btn-light dishes_each">T</button>
				</li>
				<li class="letter">
					<button type="button" class="btn btn-app btn-light dishes_each">Y</button>
				</li>
				<li class="letter">
					<button type="button" class="btn btn-app btn-light dishes_each">U</button>
				</li>
				<li class="letter">
					<button type="button" class="btn btn-app btn-light dishes_each">I</button>
				</li>
				<li class="letter">
					<button type="button" class="btn btn-app btn-light dishes_each">O</button>
				</li>
				<li class="letter">
					<button type="button" class="btn btn-app btn-light dishes_each">P</button>
				</li>
				<li class="letter keyboard_a">
					<button type="button" class="btn btn-app btn-light dishes_each">A</button>
				</li>
				<li class="letter">
					<button type="button" class="btn btn-app btn-light dishes_each">S</button>
				</li>
				<li class="letter">
					<button type="button" class="btn btn-app btn-light dishes_each">D</button>
				</li>
				<li class="letter">
					<button type="button" class="btn btn-app btn-light dishes_each">F</button>
				</li>
				<li class="letter">
					<button type="button" class="btn btn-app btn-light dishes_each">G</button>
				</li>
				<li class="letter">
					<button type="button" class="btn btn-app btn-light dishes_each">H</button>
				</li>
				<li class="letter">
					<button type="button" class="btn btn-app btn-light dishes_each">J</button>
				</li>
				<li class="letter">
					<button type="button" class="btn btn-app btn-light dishes_each">K</button>
				</li>
				<li class="letter keyboard_l">
					<button type="button" class="btn btn-app btn-light dishes_each">L</button>
				</li>
				<li class="letter keyboard_bk">
					<button type="button" class="btn btn-app btn-light dishes_each">返回</button>
				</li>
				<li class="letter">
					<button type="button" class="btn btn-app btn-light dishes_each">Z</button>
				</li>
				<li class="letter">
					<button type="button" class="btn btn-app btn-light dishes_each">X</button>
				</li>
				<li class="letter">
					<button type="button" class="btn btn-app btn-light dishes_each">C</button>
				</li>
				<li class="letter">
					<button type="button" class="btn btn-app btn-light dishes_each">V</button>
				</li>
				<li class="letter">
					<button type="button" class="btn btn-app btn-light dishes_each">B</button>
				</li>
				<li class="letter">
					<button type="button" class="btn btn-app btn-light dishes_each">N</button>
				</li>
				<li class="letter">
					<button type="button" class="btn btn-app btn-light dishes_each">M</button>
				</li>
				<li class="letter keyboard_bks">
					<button type="button" class="btn btn-app btn-light dishes_each">退格</button>
				</li>
			</ul>
		</div>
		<div class="modal fade" id="configModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
						<h4 class="modal-title">服务端配置</h4>
					</div>
					<div class="modal-body">
						<label class="block clearfix config">
							<span class="block input-icon input-icon-right">
								<span class="label_name">服务地址：</span>
								<div>
									<select id='serverAgree' class="pull-left">
										<option value='http://'>http://</option>
										<option value='https://'>https://</option>
									</select>
									<input type="text" class="form-control pull-left setUpInput" id="server" name="server" placeholder="IP:端口号"/>
								</div>
							</span>
						</label>
						<label class="block clearfix config">
							<span class="block input-icon input-icon-right">
								<span class="label_name">包名：</span>
								<input type="text" class="form-control" id="packageName" name="packageName" placeholder="huasheng"/>
							</span>
						</label>
						<label class="block clearfix config">
							<span class="block input-icon input-icon-right">
								<span class="label_name">更新地址：</span>
								<div>
									<select id='updaterUrlAgree' class='pull-left'>
										<option value='http://'>http://</option>
										<option value='https://'>https://</option>
									</select>
									<input type="text" class="form-control pull-left setUpInput" id="updaterUrl" name="updaterUrl" placeholder="IP:端口号/文件夹名/"/>
								</div>
								</span>
						</label>
					</div>
					<div class="modal-footer">
						<button class="btn btn-primary btn-xs" id='openConfig'><i class="ace-icon fa fa-cog"></i>config.json路径</button>
						<button class="btn btn-primary btn-xs" id='checkServer'><i class="ace-icon fa fa-cog"></i>校验服务地址</button>
						<button class="btn btn-primary btn-xs" id='checkPackage'><i class="ace-icon fa fa-cog"></i>校验包名</button>
						<button class="btn btn-primary btn-xs" id='checkUpdate'><i class="ace-icon fa fa-cog"></i>校验更新地址</button>
						<button class="btn btn-primary btn-xs" id='configSave'><i class="ace-icon fa fa-check"></i>提交更改</button>
						<button class="btn btn-danger btn-xs" data-dismiss="modal"><i class="ace-icon fa fa-times"></i>关闭</button>
					</div>
				</div>
			</div>
		</div>
    </body>
	<script src="../../assets/js/jquery.validate.js"></script>
    <script src="../../assets/js/bootstrap.js"></script>
    <script src="../../assets/js/ace/ace.js"></script>
    <script src="../../assets/js/bootbox.js"></script>
    <script src="../../js/huasheng.js"></script>
	<script src="../../js/login/login.js"></script>
	<script src="../../assets/js/jquery.gritter.js"></script>

	<script>
		$(document).ready(function(){

			//菜单
			electron.ipcRenderer.send('setLoginMenu');

			//版本号
			$("#id-version").html($.HSAPI_GETVERSION());
			//更新
			$.HSAPI_UPDATEAUTO((oper)=>{
				switch(oper){
					case '-1':
						$("#updateIcon").removeClass('fa-check').addClass('fa-times red');
						$("#updateMess").html('检查更新失败');
						$("#updateMess").addClass('red');
						break;
					case '1':
						$("#updateIcon").removeClass('fa-check').addClass('fa-cloud-download updateIco');
						$("#updateMess").html('有更新');
						$("#updateIcon").unbind('click').bind('click',function(){
							$.HSAPI_UPDATEDOWNLOAD();
						});
						break;
				}
			});

			//打开配置模态
			$("#configButton").bind("click",function(){
				//读取配置文件
				let configValue=electron.ipcRenderer.sendSync('getConfigMess');

				let server=configValue.HSAPI_SERVER;
				if(server!=''){
					let serverArray=server.split('://'); 
					let serverAgree=serverArray[0];
					server=serverArray[1];
					$("#serverAgree").val(serverAgree+'://');
					$("#server").val(server);
				}else{
					$("#serverAgree").val('http://');
					$("#server").val(server);
				}

				let updaterUrl=configValue.HSAPI_UPDATERURL;
				if(updaterUrl!=''){
					let updaterUrlArray=updaterUrl.split('://'); 
					let serverAgree=updaterUrlArray[0];
					updaterUrl=updaterUrlArray[1];
					$("#updaterUrlAgree").val(serverAgree+'://');
					$("#updaterUrl").val(updaterUrl);
				}else{
					$("#updaterUrlAgree").val('http://');
					$("#updaterUrl").val(updaterUrl);
				}

				$("#packageName").val(configValue.HSAPI_PACKAGENAME);
				$("#configModal").modal("show");
			});

			//打开配置文件目录
			$("#openConfig").bind("click",function(){
				electron.ipcRenderer.send('openConfigFile');
			});
			//校验服务地址
			$("#checkServer").bind("click",function(){
				electron.ipcRenderer.send('openTest',$("#serverAgree").val()+$("#server").val());
			});
			//校验包地址
			$("#checkPackage").bind("click",function(){
				electron.ipcRenderer.send('openTest',$("#serverAgree").val()+$("#server").val()+'/'+$("#packageName").val());
			});
			//校验更新地址
			$("#checkUpdate").bind("click",function(){
				electron.ipcRenderer.send('openTest',$("#updaterUrlAgree").val()+$("#updaterUrl").val());
			});
			//提交更改
			$("#configSave").bind("click",function(){
				//读取配置文件
				let configValue=electron.ipcRenderer.sendSync('getConfigMess');
				let configMess={};
				configMess.server=$("#serverAgree").val()+$("#server").val();
				configMess.packageName=$("#packageName").val();
				jQuery.ajax({  
					type : 'get',
					url : $("#updaterUrlAgree").val()+$("#updaterUrl").val(),  
					sync:false,
					success:function(data){
						configMess.updaterUrl=$("#updaterUrlAgree").val()+$("#updaterUrl").val();
						let mode=$("input[value='"+configValue.HSAPI_FULLSCREEN+"']:checked").attr("value");
						configMess.fullscreen=mode;
						electron.ipcRenderer.send('saveConfigMess',configMess);
					},
					error : function(data){  
						configMess.updaterUrl=$("#updaterUrlAgree").val();
						let mode=$("input[value='"+configValue.HSAPI_FULLSCREEN+"']:checked").attr("value");
						configMess.fullscreen=mode;
						electron.ipcRenderer.send('saveConfigMess',configMess);
					}
				});
				
			});

			//历史记录读取
			let configValue=electron.ipcRenderer.sendSync('getConfigMess');
			if(configValue.HSAPI_FULLSCREEN=="")
				configValue.HSAPI_FULLSCREEN="pc"
			$("input[value='"+configValue.HSAPI_FULLSCREEN+"']").attr("checked",true);
			$("#hotelID").val(configValue.HSAPI_HOTELID);
			$("#bmh").val(configValue.HSAPI_BMH);
			if(configValue.HSAPI_HOTELID!='')
				$("#id-disable-check").attr("checked",true);

			if(configValue.his_hotelID&&false){
				var arr = configValue.his_hotelID.split(",");
				var html = '';
				var max = arr.length<3?arr.length:3;
				for(var i=0;i<max;i++){
					var v = arr[i];
					html += '<button type="button" data-value="'+v+'" style="height:33px;margin-top:-4px;" class="btn btn-white btn-purple btn-sm btn-his_hotelID">'+v+'</button>'
				}
				// $(arr).each(function(k,v){
				// 	html += '<button type="button" data-value="'+v+'" style="height:33px;margin-top:-4px;" class="btn btn-white btn-purple btn-sm btn-his_hotelID">'+v+'</button>'
				// })
				$("#his_hotelID").html(html);
				$(".btn-his_hotelID").unbind("click").click(function(){
					var value = $(this).data("value")||$(this).attr("data-value");
					$("#hotelID").val(value);
				})
				$("#hotelID").css({"width":"100"});
			}

			if(configValue.his_bmh&&false){
				var arr = configValue.his_bmh.split(",");
				var html = '';
				var max = arr.length<3?arr.length:3;
				for(var i=0;i<max;i++){
					var v = arr[i];
					html += '<button type="button" data-value="'+v+'" style="height:33px;margin-top:-4px;" class="btn btn-white btn-purple btn-sm btn-his_bmh">'+v+'</button>'
				}
				// $(arr).each(function(k,v){
				// 	html += '<button type="button" data-value="'+v+'" style="height:33px;margin-top:-4px;" class="btn btn-white btn-purple btn-sm btn-his_bmh">'+v+'</button>'
				// })
				$("#his_bmh").html(html);
				$(".btn-his_bmh").unbind("click").click(function(){
					var value = $(this).data("value")||$(this).attr("data-value");
					$("#bmh").val(value);
				})
				$("#bmh").css({"width":"100"});
			}

			//是否全屏模式
			$("input[name='fullScreenMode']").bind("click",function(){
				let mode=$(this).attr("value");
				let configValue=electron.ipcRenderer.sendSync('getConfigMess');

				configValue.server=configValue.HSAPI_SERVER;
				configValue.packageName=configValue.HSAPI_PACKAGENAME;
				configValue.updaterUrl=configValue.HSAPI_UPDATERURL;
				configValue.hotelID=configValue.HSAPI_HOTELID;
                configValue.bmh=configValue.HSAPI_BMH;
				configValue.fullscreen=mode;
				
				electron.ipcRenderer.send('saveConfigMess',configValue,false);
			});
		})

	</script>
</html>